<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page language="java" import="com.server.web.JsVersionUtil"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>所有用户</title>
<script type="text/javascript"
	src='<c:url value="/js/boot.js"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>'></script>
<script type="text/javascript"
	src='<c:url value="/js/rqfui/rqfui.js"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>'></script>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>' />
<style type="text/css">
body {
	height: 100%;
	width: 100%;
}
</style>
</head>
<body>
	<div class="mini-toolbar" style="text-align: left; line-height: 30px;"
		borderStyle="border:0;">
		<label>登录名/姓名：</label> <input id="key1" class="mini-textbox"
			style="width: 150px;" onenter="onKeyEnter1" /> <a
			class="mini-button" iconCls="icon-search" style="width: 60px;" onclick="search1()">查询</a> <a
			class="mini-button" iconCls="icon-broom" style="width: 60px;" onclick="clear()">清除</a> <a
			class="mini-button" iconCls="icon-ok" style="width: 60px;" onclick="ok()">确定</a>
	</div>
	<div class="mini-fit">
		<div id="splitterPan" class="mini-splitter"
			style="width: 100%; height: 100%;" handlerSize="0">
			<div id='panLeft' size="50%" showCollapseButton="true"
				style="padding: 0px; height: 100%; width: 50%;">
				<div>普通用户</div>
				<div class="mini-fit">
					<div id="usrGrid1" class="mini-datagrid" pagesize="50"
						ondrawcell="ondatagrid1DrawCell" onrowdblclick="choosePerson"
						idField="id" multiSelect="true" showColumns="true"
						url='<c:url value="/common/users"></c:url>'
						borderStyle="border-width:0;border-top-width:1px;"
						style="height: 100%; width: 100%; -moz-user-select: none; -webkit-user-select: none;">
						<div property="columns">
							<div type="checkcolumn"></div>
							<div field="nickname" width="100%" headerAlign="center"
								allowSort="false">昵称</div>
							<div field="name" width="100px" headerAlign="center"
								allowSort="false">姓名</div>
						</div>
					</div>
				</div>
			</div>
			<div id="panRight" showCollapseButton="true" expanded="true"
				style="overflow: hidden;">
				<div>管理员用户</div>
				<div class="mini-fit">
					<div id="usrGrid2" class="mini-datagrid" pagesize="50"
						ondrawcell="ondatagrid2DrawCell" onrowdblclick="choosePerson"
						idField="id" multiSelect="true" showColumns="true"
						url='<c:url value="/common/mngUsers"></c:url>'
						borderStyle="border-width:0;border-top-width:1px;"
						style="height: 100%; width: 100%; -moz-user-select: none; -webkit-user-select: none;">
						<div property="columns">
							<div type="checkcolumn"></div>
							<div field="nickname" width="100%" headerAlign="center"
								allowSort="false">昵称</div>
							<div field="name" width="100px" headerAlign="center"
								allowSort="false">姓名</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		mini.parse();
		mini_debugger = false;

		var gridFilter1 = gridFilter();

		var usrGrid1 = mini.get("usrGrid1");
		var usrGrid2 = mini.get("usrGrid2");
		
		var data = new Object();

		usrGrid1.load();
		usrGrid2.load();

		function onKeyEnter1(e) {
			search1();
		}
		//查询
		function search1() {
			gridFilter1.clearFilterData();
			var key = mini.get("key1").getValue();
			if (key != "") {
				var filter1 = gridFilter1.formFilterData("nickname", key, '',
						"CONTAIN", "OR");
				var filter2 = gridFilter1.formFilterData("name", key, '',
						"CONTAIN", "OR");
				gridFilter1.addFilterData(filter1);
				gridFilter1.addFilterData(filter2);

				var filters = gridFilter1.getFilterData();
				var postData = new Object();
				if (filters != null || filters.length > 0) {
					postData.filterdata = mini.encode(filters);
				}
				usrGrid1.load(postData);
				usrGrid2.load(postData);
			}
		}
		//清除
		function clear(){
			gridFilter1.clearFilterData();
			mini.get("key1").setValue();
			usrGrid1.load({});
			usrGrid2.load({});
		}
		//确定
		function ok(){
			var names = null;
			var uuids = null;
			var rows1 = usrGrid1.getSelecteds();
			var rows2 = usrGrid2.getSelecteds();
			var length1 = rows1.length;
			var length2 = rows2.length;
			if(length1 == 0 && length2 == 0){
				top.commonTools.showTip("请选择人员！", 2);
				return;
			}
			for(var i=0; i<length2; i++){
				var row = rows2[i];
				var nickname = row.nickname;
				if(names == null){
					names = nickname+'(管理员)';
				}else{
					names += ','+nickname+'(管理员)';
				}
				var uuid = row.uuid;
				if(uuids == null){
					uuids = uuid;
				}else{
					uuids += ','+uuid;
				}
			}
			for(var i=0; i<length1; i++){
				var row = rows1[i];
				var nickname = row.nickname;
				if(names == null){
					names = nickname;
				}else{
					names += ','+nickname;
				}
				var uuid = row.uuid;
				if(uuids == null){
					uuids = uuid;
				}else{
					uuids += ','+uuid;
				}
			}
			if(uuids == null){
				top.commonTools.showTip("没有可添加的人员！", 2);
				return;
			}
			data.names = names;
			data.uuids = uuids;
			CloseWindow('ok');
		}
		function ondatagrid1DrawCell(e) {
			var field = e.field;
		}
		function ondatagrid2DrawCell(e) {
			var field = e.field;
		}
		
		function CloseWindow(action) {
			if (window.CloseOwnerWindow)
				return window.CloseOwnerWindow(action);
			else
				window.close();
		}
	
		function onOk() {
			var rows = orgGrid.getSelected();
			if(typeof rows!="undefined" && rows!=null){
				CloseWindow("ok");
			}else{
				mini.alert("请选择部门。");
			}
		}
		

		function addToList(LoginName, UserName, orgNo, orgName) {
			if (typeof parent.addPerson != "undefined") {
				parent.addPerson(LoginName, UserName, orgNo, orgName);
			}
		}
		function checkOrgNo(loginName, name) {
			var messageid = parent.mini.loading("操作中...", "Loading");
			$.ajax({
				url : '<c:url value="/org/getUserOrgCount"></c:url>/'
						+ loginName,
				type : "post",
				dataType : 'json',
				timeout : 30000,
				success : function(text) {
					if (typeof text != "undifined") {
						var orgCount = new Number(text.totalCount);
						if (orgCount == 1) {
							addToList(loginName, name, text.orgNo,
									text.orgName);
						} else if (orgCount == 0) {
							top.commonTools.showTip(
									"要添加的人员在系统中不属于任何部门，无法为他添加办理!", 2);
						} else if (orgCount >= 1) {
							openOrgChoose(loginName, name);
						}
					}
				},
				complete : function(XMLHttpRequest, textStatus) {
					if (messageid != null) {
						parent.mini.hideMessageBox(messageid);
					}
				},
				error : function(xhr, textStatus) {
					if (textStatus == 'timeout') {
						top.commonTools.showTip("操作超时!", 2);
					} else {
						top.commonTools.showTip("添加人员操作出错!", 2);
					}
				}
			});
		}
	</script>
</body>
</html>